package com.tanhua.dubbo.server.api;

import com.alibaba.dubbo.config.annotation.Service;
import com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector;
import com.tanhua.dubbo.server.pojo.TaoHua;
import org.apache.commons.lang3.StringUtils;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@Service(version = "1.0.0")
public class TaoHuaApiImpl implements TaoHuaApi{

    @Autowired
    private MongoTemplate mongoTemplate;

    /**
     * 保存语音对象
     * @param taoHua
     * @return
     */
    @Override
    public Boolean saveSound(TaoHua taoHua) {

        /*Query qurey=Query.query(Criteria.where("id").is(taoHua.getId()));
        TaoHua taoHuaFind = this.mongoTemplate.findOne(qurey, TaoHua.class);
        if (null!=taoHuaFind){
            return false;
        }*/
        taoHua.setId(ObjectId.get());
        this.mongoTemplate.save(taoHua);
        return true;
    }

    @Override
    public List<TaoHua> findSound() {
        List<TaoHua> all = this.mongoTemplate.findAll(TaoHua.class);
        return all;
    }


}
